package com.acwing.partition15;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @author `RKC`
 * @date 2022/3/29 21:39
 */
public class AC1470水桶传递队列 {

    private static final int N = 110;
    private static final int[][] dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    private static char[][] g = new char[11][11];
    private static int[][] dist = new int[11][11];
    private static Queue<int[]> q = new ArrayDeque<>(N);

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int[] b = new int[2], l = new int[2];
        for (int i = 0; i < 10; i++) {
            String s = reader.readLine();
            for (int j = 0; j < 10; j++) {
                g[i][j] = s.charAt(j);
                if (g[i][j] == 'B') b = new int[]{i, j};
                else if (g[i][j] == 'L') l = new int[]{i, j};
            }
        }
        writer.write(bfs(b, l) + "\n");
        writer.flush();
    }

    private static int bfs(int[] start, int[] end) {
        q.add(start);
        dist[start[0]][start[1]] = 1;
        while (!q.isEmpty()) {
            int[] u = q.poll();
            int x = u[0], y = u[1];
            if (x == end[0] && y == end[1]) return dist[x][y] - 2;
            for (int[] dir : dirs) {
                int nx = x + dir[0], ny = y + dir[1];
                if (nx < 0 || ny < 0 || nx >= 10 || ny >= 10 || g[nx][ny] == 'R' || dist[nx][ny] != 0) continue;
                dist[nx][ny] = dist[x][y] + 1;
                q.add(new int[]{nx, ny});
            }
        }
        return -1;
    }
}
